{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import wx\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# 定义一个自定义的 wx.Frame 子类\n",
    "class MyFrame(wx.Frame):\n",
    "    def __init__(self, parent, title):\n",
    "        # 调用父类的构造函数\n",
    "        super(MyFrame, self).__init__(parent, title=title, size=(300, 200))\n",
    "\n",
    "        # 创建一个面板\n",
    "        self.panel = wx.Panel(self)\n",
    "\n",
    "        # 创建一个按钮\n",
    "        button = wx.Button(self.panel, label=\"点击我\", pos=(100, 70))\n",
    "\n",
    "        # 绑定按钮的点击事件到 on_button_click 方法\n",
    "        button.Bind(wx.EVT_BUTTON, self.on_button_click)\n",
    "\n",
    "        # 显示窗口\n",
    "        self.Show()\n",
    "\n",
    "    def on_button_click(self, event):\n",
    "        # 当按钮被点击时，弹出一个消息框\n",
    "        wx.MessageBox(\"你点击了按钮！\", \"消息\", wx.OK | wx.ICON_INFORMATION)\n",
    "\n",
    "        # 创建一个按钮\n",
    "        button33 = wx.Button(self.panel, label=\"点击我2\", pos=(100, 90))\n",
    "\n",
    "        # 绑定按钮的点击事件到 on_button_click 方法\n",
    "        button33.Bind(wx.EVT_BUTTON, self.on_button_click2)\n",
    "    def on_button_click2(self, event):\n",
    "        wx.MessageBox(\"你点击了按钮！on_button_click2\", \"消息\", wx.OK | wx.ICON_INFORMATION)\n",
    "\n",
    "# 定义一个自定义的 wx.App 子类\n",
    "class MyApp(wx.App):\n",
    "    def OnInit(self):\n",
    "        # 创建一个 MyFrame 实例\n",
    "        frame = MyFrame(None, \"wxPython 示例\")\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "app = MyApp()\n",
    "app.MainLoop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
